package br.com.puertorico.common.utils;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;

/**
 * Class Formatador.
 */
public class Formatador {

	/** O atributo locale. */
	private static Locale locale = new Locale("pt", "BR");

	/** A constante REAL. */
	private static final DecimalFormatSymbols REAL = new DecimalFormatSymbols(
			locale);

	/**
	 * Get locale brasil.
	 *
	 * @return the locale brasil
	 * @see Formatador#localeBrasil.
	 */
	public static Locale getLocaleBrasil() {
		return locale;
	}

	/**
	 * Formatar cnpj.
	 *
	 * @param cnpj
	 *            - cnpj
	 * @return string
	 */
	public static String formatarCnpj(String cnpj) {
		if (cnpj == null) {
			return null;
		}
		return cnpj.toString().replaceAll(
				"^(\\d{2})(\\d{3})(\\d{3})(\\d{4})(\\d{2})$", "$1.$2.$3/$4-$5");
	}

	public static String formatarCpf(String cpf) {
		if (cpf == null) {
			return null;
		}
		return cpf.replaceAll("^(\\d{3})(\\d{3})(\\d{3})(\\d{2})$",
				"$1.$2.$3-$4");
	}

	/**
	 * Formatar cep.
	 *
	 * @param cep
	 *            - cep
	 * @return string
	 */
	public static String formatarCep(String cep) {
		if (cep == null) {
			return null;
		}
		return cep.toString().replaceAll("^(\\d{5})(\\d{3})$", "$1-$2");
	}

	/**
	 * Formatar moeda.
	 *
	 * @param numero
	 *            - numero
	 * @return string
	 */
	public static String formatarMoeda(BigDecimal numero) {
		if (numero == null) {
			return null;
		}
		DecimalFormat formater = new DecimalFormat("###,###,##0.00", REAL);

		return formater.format((Number) numero);
	}

}
